package net.sppan.base.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;

//@Configuration
public class RedisConfig {

    @Value("${spring.redis.database}")
    private int database;
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.pool.max-active}")
    private int maxActive;
    @Value("${spring.redis.pool.max-idle}")
    private int maxIdle;
    @Value("${spring.redis.pool.min-idle}")
    private int minIdle;
    @Value("${spring.redis.pool.max-wait}")
    private int maxWait;

    @Bean
    public JedisPoolConfig getJedisPoolConfig() {
                JedisPoolConfig config = new JedisPoolConfig();
                 config.setMaxIdle(maxIdle);
                 config.setMaxWaitMillis(maxWait);
                 config.setMaxTotal(maxActive);
                 return config;
             }

    @Bean
      public JedisPool getJedisPool() {
        return new JedisPool(getJedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, password);
    }
}
